﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Data.SqlClient;
using System.Data.Common;
using System.Web.UI.WebControls;




public partial class register : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void rebt_Click(object sender, EventArgs e)
    {
        string Sql = "Data Source=.;Initial Catalog=smdb;Integrated Security=True";


        using (SqlConnection scon = new SqlConnection(Sql))
        {

            scon.Open();
            string sql = "select count(*) from users where name= '"+renametext.Text.Trim()+"'";//uid是什么类型，假设为整形，如果是字符串加单引号
            SqlCommand cmd = new SqlCommand(sql, scon);
            int row = (int)cmd.ExecuteScalar();//row大于等于1，有重复结构
            scon.Close();
            if (row > 0)
            {
                //提示注册失败
                Response.Write("用户名重复！");
            }
            else
            {
                //添加新用户
                string str = "insert into [users](name,psd ) values('" + renametext.Text.Trim() + "','" + repswtext.Text.Trim() + "')";

                scon.Open();
                SqlCommand command = new SqlCommand
                {
                    Connection = scon,
                    CommandText = str
                };
                int obj = command.ExecuteNonQuery();
               


                HttpContext.Current.Response.Redirect("login.aspx");
            }

            






        }
    }
}